﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WikiTrailCreator.TrailImages;
using WikiTrailCreator.SpecialDialogs;

namespace WikiTrailCreator.TextboxInABox
{
    public partial class ucTextboxInAGroupBox : UserControl
    {
        public ucTextboxInAGroupBox()
        {
            InitializeComponent();
        }

        [Browsable(true)]
        public string LabelBlurb
        {
            get { return labelBlurb.Text; }
            set { labelBlurb.Text = value; }
        }

        [Browsable(true)]
        public string GroupBoxText
        {
            get { return groupBox.Text; }
            set { groupBox.Text = value; }
        }

        [Browsable(true)]
        public string TextBoxContents
        {
            get { return textBox.Text; }
            set { textBox.Text = value; }
        }

        private void insertThumbnailToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormImageSelector formImageSelector = new FormImageSelector();
            DialogResult dialogResult = formImageSelector.ShowDialog();

            if (dialogResult == DialogResult.OK)
            {
                string wikiCode = formImageSelector.GetInternalThumbnailCode();
                textBox.Text = textBox.Text.Insert(textBox.SelectionStart, wikiCode);
            }

            formImageSelector.Dispose();
        }

        private void insertGalleryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormGalleryCreator formGalleryCreator = new FormGalleryCreator();
            DialogResult dialogResult = formGalleryCreator.ShowDialog();

            if (dialogResult == DialogResult.OK)
            {
                string wikiCode = formGalleryCreator.GetInternalGalleryCode();
                textBox.Text = textBox.Text.Insert(textBox.SelectionStart, wikiCode);
            }

            formGalleryCreator.Dispose();
        }

        private void insertLinkToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormAddLink formAddLink = new FormAddLink();
            DialogResult dialogResult = formAddLink.ShowDialog();

            if (dialogResult == DialogResult.OK)
            {
                string wikiCode = formAddLink.GetLinkAsWikiText();
                textBox.Text = textBox.Text.Insert(textBox.SelectionStart, wikiCode);
            }

            formAddLink.Dispose();
        }

        [Browsable(true)]
        public new event EventHandler TextChanged
        {
            add
            {
                textBox.TextChanged += value;
            }
            remove
            {
                textBox.TextChanged -= value;
            }
        }
    }
}
